<template>
  <div class="">
    <h4>过滤器filter</h4>
    <h1>{{ time | filtime }}</h1>
    <!-- 使用的时候 | 后面跟过滤器的名字 -->
    <!-- xxx-xx-xx xx:xx:xx -->
  </div>
</template>

<script>
export default {
  data() {
    return {
      time: new Date(),
    };
  },

  methods: {},
  filters: {
    filtime(val) {
      // 过滤器默认的参数是要过滤的值
      // console.log(val);
      let time = new Date(val);
      //把val字符串转化为一个时间对象
      let year = time.getFullYear();
      let month = time.getMonth() + 1;
      let day = time.getDate();
      let hour = time.getHours();
      let minus = time.getMinutes();
      let seconds = time.getSeconds();

      return `${year}-${month}-${day} ${hour}:${minus}:${seconds}`;
      //必须有return 值 返回过滤的结果
    },
  },
};
</script>

<style lang="scss"></style>
